/**
 * created by guyi 2018.1.19
 */
var express = require('express');
var router = express.Router();
var Post = require('../models/Post');
var superagent = require('superagent');
require('superagent-proxy')(superagent);
var jwt = require('jsonwebtoken');
var redis = require("redis");
var yzmService = require("../routes/yzmService");
var client = redis.createClient(6379, "127.0.0.1");
var UserService = require('../services/UserService');
const PostService = require('../services/PostService');
var moment = require('moment');
var fs = require('fs');

async function test(req, res, next) {
    // var proxy = 'http://113.77.243.210:9797';
    // var stream = fs.createWriteStream('./test.jpg');
    var test = superagent
        .get('http://jxfw.gdut.edu.cn/yzm?d=1516699875395')
        // .proxy(proxy)
        .set( {'Accept': '*/*',
        'Accept-Language': 'en-US,en;q=0.8',
        'Cache-Control': 'max-age=0',
        'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36',
        'Connection': 'keep-alive',
        // 'Content-Type': 'image/png',
        // 'Content-Type' : 'application/octet-stream	'
        
        })
        // .pipe(stream)
        .end((err, resp) => {
            if (err) {
                console.log(err);
            } else {
                fs.writeFile('./test.jpg', resp.body, 'binary', (err, result) =>{
                    // console.log('ok')
                })
                // console.log(resp.files)
                res.send(resp);
            }
        }) 
}
async function test2() {
    superagent.get('http://api.xicidaili.com/free2016.txt')
    .end((err, resp) => {
        console.log(resp.body);
        fs.writeFile('./test.txt', resp.body, (err, result) =>{
            console.log('ok')
        })
    })
}

module.exports = {test, test2}